package com.zhangck.bos2_0.Service.system.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zhangck.bos2_0.Service.system.MenuService;
import com.zhangck.bos2_0.dao.system.MenutRepository;

import cn.itcast.bos.domain.system.Menu;
import cn.itcast.bos.domain.system.User;

/** 
* @author 上午茶
* @version 创建时间：2018年6月18日 下午4:32:32 
* 类说明 
*/
@Service
@Transactional
public class MenuServiceImpl implements MenuService {

	@Autowired
	private MenutRepository menutRepository;
	
	@Override
	public void save(Menu model) {
		menutRepository.save(model);
	}

	@Override
	public List<Menu> findAll() {
		return menutRepository.findAll();
	}

	@Override
	public Page<Menu> findAll(Pageable pageable) {
		return menutRepository.findAll(pageable);
	}

	@Override
	public List<Menu> findByUser(User user) {
		if (user.getUsername().equals("lisi")) {
			return menutRepository.findAll();
		}
		return menutRepository.findByUser(user.getId());
	}

	@Override
	public void delete(Menu model) {
		menutRepository.delete(model);
	}

}
